package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;

import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.PhoneExtEnum;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.SupplierContactEnum;
import com.xbongbong.saas.enums.dictionary.ContactLevelEnum;
import com.xbongbong.saas.enums.dictionary.SexEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.xbongbong.sys.enums.RoleEnum;
import lombok.Getter;

/**
 * 供应商联系人
 * @author Jian.Wang
 * @date 2019/1/16 20:25
 * @since v1.0
 * @version v1.0
 */
@Getter
public enum TempSupplierContactEnum {

    BASE_INFO(SupplierContactEnum.BASE_INFO),
    NAME(SupplierContactEnum.NAME),
    PHONE(SupplierContactEnum.PHONE),
    SUPPLIER_ID(SupplierContactEnum.SUPPLIER_ID),
    ADDRESS(SupplierContactEnum.ADDRESS),
    EMAIL(SupplierContactEnum.EMAIL),
    QQ(SupplierContactEnum.QQ),
    SEX(SupplierContactEnum.SEX),
    BIRTHDAY(SupplierContactEnum.BIRTHDAY),
    MEMO(SupplierContactEnum.MEMO),

    EXTEND_INFO(SupplierContactEnum.EXTEND_INFO),
    DEPARTMENT(SupplierContactEnum.DEPARTMENT),
    POSITION(SupplierContactEnum.POSITION),
    LEVEL(SupplierContactEnum.LEVEL),

    SYSTEM_INFO(SupplierContactEnum.SYSTEM_INFO),
    CREATOR_ID(SupplierContactEnum.CREATOR_ID),
    ADD_TIME(SupplierContactEnum.ADD_TIME),
    UPDATE_TIME(SupplierContactEnum.UPDATE_TIME),

    SUPPLIER_ID_LINK_TEXT(SupplierContactEnum.SUPPLIER_ID_LINK_TEXT),
    BIRTHDAY_FLAG(SupplierContactEnum.BIRTHDAY_FLAG),
    BIRTHDAY_MMDD(SupplierContactEnum.BIRTHDAY_MMDD),
    USER_ID(SupplierContactEnum.USER_ID),
    IS_MAIN(SupplierContactEnum.IS_MAIN),
    OWNER_ID(SupplierContactEnum.OWNER_ID),
    COUSERID(SupplierContactEnum.COUSERID),
    ;

    private SupplierContactEnum anEnum;

    TempSupplierContactEnum(SupplierContactEnum supplierContactEnum) {
        this.anEnum = supplierContactEnum;
    }

    public static List<TempSupplierContactEnum> getAllEnum() {
        List<TempSupplierContactEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initName(FieldAttrEntity fieldAttrEntity){
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.SUPPLIER_CONTACT.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.SUPPLIER_CONTACT.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(NAME.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化级别下拉
     * @author Jian.Wang
     * @date 2019/1/16 20:34
     */
    public static void initLevel(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(ContactLevelEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(1);
    }

    /**
     * 初始化性别
     *
     * @param fieldAttrEntity 字段解释实体
     */
    public static void initSex(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(SexEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(1);
    }


    /**
     * 初始化关联供应商
     *
     * @param fieldAttrEntity 字段解释实体
     */
    public static void initSupplierName(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.SUPPLIER.getCode());
        fieldAttrEntity.setLinkedText(SUPPLIER_ID_LINK_TEXT.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }
    /**
     * 初始化联系电话
     *
     * @param fieldAttrEntity 字段解释实体
     */
    public static void initPhone(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity item = InitExplainsHelper.setField("text_1", "类型", "type", FieldTypeEnum.COMBO.getType(), 4, 1, 0, 1);
//        String str = "工作,手机,住址,主要,传真,其他";
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(PhoneExtEnum.class, FieldTypeEnum.COMBO.getType());
        itemPoJoList.get(0).setChecked(true);
        item.setItems(itemPoJoList);
        item.setRequired(1);
        item.setParentAttr(PHONE.anEnum.getAttr());
        item.setDictionaryFlag(1);
        items.add(item);
        FieldAttrEntity item2 = InitExplainsHelper.setField("text_2", "电话", "phone", FieldTypeEnum.TEXT.getType(), 4, 1, 0, 1);
        item2.setRequired(1);
        item.setParentAttr(PHONE.anEnum.getAttr());
        items.add(item2);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("custom");
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setRequired(1);
        fieldAttrEntity.setIsForbidden(0);
    }
    /**
     * 初始化生日
     *
     * @param fieldAttrEntity 实体
     * @author feng.zheng
     * @date 2019/2/14 15:53
     */
    public static void initBirthday(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedText(BIRTHDAY_FLAG.anEnum.getAttr());
        fieldAttrEntity.setDateType(DateTimeEnum.TIME.getType());
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setShowType(ShowTypeEnum.ALL.getCode());
        fieldAttrEntity.setEditHide(0);
        fieldAttrEntity.setRequired(1);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        //可删除权限：默认【超级管理员、销售主管】可删除负责人，支持自定义；
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setMultiple(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }

    /**
     * 初始化协同人字段
     *
     * @param fieldAttrEntity
     */
    public static void initCoUserId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setShowType(ShowTypeEnum.ALL.getCode());
        fieldAttrEntity.setFormPermission(BasicConstant.ONE);
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setEditable(1);
        //可新增权限：超级管理员、老板、销售主管、创建人、负责人、负责人主管
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setSetType(3);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }

}
